package com.gf.pf.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.gf.pf.model.Department;
import com.gf.pf.model.Ztree;

/**
 * @describe 部门
 * @date     2015年3月7日
 */
public interface DepartmentMapper {
	
	/**
	 * 根据ID查询部门SQL
	 */
	final String GET_BY_ID = "SELECT department_id as id, department_name, department_parent_id, department_memo, department_orderno, department_isvalid FROM sys_department WHERE department_id = #{depId} ORDER BY department_orderno";
	
	/**
	 * 根据ID查询根目录下的部门
	 */
	final String GET_ZTREE_BY_ID = "SELECT department_id as id, department_parent_id as pId, department_name as name FROM sys_department WHERE department_isvalid = 1 start with department_parent_id = '-1' connect by prior department_id = department_parent_id ORDER BY department_orderno";
	
	/**
	 * 保存部门SQL
	 */
	final String SAVE_DEP = "INSERT　INTO sys_department VALUES(#{id}, #{departmentName}, #{departmentParentId}, #{departmentMemo}, #{departmentOrderno}, #{departmentIsvalid})";
	
	/**
	 * 部门修改SQL
	 */
	final String MODIFY_DEP = "UPDATE sys_department SET department_name = #{departmentName}, department_memo = #{departmentMemo}, department_orderno = ${departmentOrderno}, department_isvalid = ${departmentIsvalid}  WHERE department_id = #{id}";
	
	/**
	 * 删除部门SQL
	 */
	final String DELETE_DEP = "DELETE FROM sys_department WHERE department_id = #{depId}";
	
	/**
	 * 
	 * @describe 根据ID查询部门
	 * @param depId
	 * @return
	 */
	@Select(GET_BY_ID)
	Department getDep(String depId);
	
	/**
	 * 
	 * @description 根据ID查询根目录下的部门
	 * @return List<Ztree>
	 */
	@Select(GET_ZTREE_BY_ID)
	List<Ztree> getDepartmentZtree();
	
	/**
	 * 
	 * @description 保存部门
	 * @return Integer
	 */
	@Insert(SAVE_DEP)
	Integer saveDep(Department dep);
	
	/**
	 * 
	 * @description 部门修改
	 * @return Integer
	 */
	@Update(MODIFY_DEP)
	Integer modifyDep(Department dep);
	
	/**
	 * 
	 * @description 部门删除
	 * @return Integer
	 */
	@Update(DELETE_DEP)
	Integer deleteDep(String depId);
}
